package com.example.arithmeticleetcode.leetcode.jan;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2021-01-25 09:14
 **/
public class Demo20 {



    /**
     * 1507. 转变日期格式
     *
     * @param date
     * @return
     */
    public String reformatDate(String date) {
        Map<String, String> map = new HashMap<>();
        map.put("Jan", "01");
        map.put("Feb", "02");
        map.put("Mar", "03");
        map.put("Apr", "04");
        map.put("May", "05");
        map.put("Jun", "06");
        map.put("Jul", "07");
        map.put("Aug", "08");
        map.put("Sep", "09");
        map.put("Oct", "10");
        map.put("Nov", "11");
        map.put("Dec", "12");
        String[] split = date.split(" ");
        return split[2] + "-" + map.get(split[1]) + "-" + (split[0].length() == 3 ? "0" : "") + split[0].substring(0, split[0].length() - 2);
    }

    public static void main(String[] args) {
        thousandSeparator(123456789);
    }

    /**
     * 1556. 千位分隔数
     *
     * @param n
     * @return
     */
    public static String thousandSeparator(int n) {
        String retStr = String.valueOf(n);
        if (n < 1000) return retStr;
        char[] chars = retStr.toCharArray();
        StringBuilder sb = new StringBuilder();
        int index = 1;
        for (int len = chars.length, i = len - 1; i >= 0; i--) {
            sb.append(chars[i]);
            if (index % 3 == 0 && index != len) {
                sb.append(".");
            }
            index++;
        }
        return sb.reverse().toString();
    }


    /**
     * 5645. 找到最高海拔
     *
     * @param gain
     * @return
     */
    public int largestAltitude(int[] gain) {
        int max = Integer.MIN_VALUE;
        int pre = 0;
        for (int i = 0; i < gain.length; i++) {
            max = Math.max(pre, max);
            pre += gain[i];
        }
        return max;
    }

    /**
     * 1736. 替换隐藏数字得到的最晚时间
     *
     * @param time
     * @return
     */
    public String maximumTime(String time) {
        char[] chars = time.toCharArray();
        StringBuilder sb = new StringBuilder();
        char proChar = '?';
        if (chars[0] == proChar) {
            if (chars[1] == proChar || chars[1] < '4') {
                sb.append("2");
            } else {
                sb.append("1");
            }
        } else {
            sb.append(chars[0]);
        }
        if (chars[1] == proChar) {
            sb.append(chars[0] == proChar || chars[0] == '2' ? '3' : '9');
        } else sb.append(chars[1]);
        sb.append(':');
        if (chars[3] == proChar) sb.append('5');
        else sb.append(chars[3]);
        if (chars[4] == proChar) sb.append('9');
        else sb.append(chars[4]);
        return sb.toString();
    }
}
